/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef GEOFENCE_HILOG_WRAPPER_H
#define GEOFENCE_HILOG_WRAPPER_H

#define CONFIG_HILOG
#ifdef CONFIG_HILOG
#include "hilog/log.h"
namespace OHOS {
namespace Msdp {
#define __FILENAME__            (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
#define __FORMATED(fmt, ...)    "[%{public}s] %{public}s# " fmt, __FILENAME__, __FUNCTION__, ##__VA_ARGS__

#ifdef GEOFENCE_HILOGF
#undef GEOFENCE_HILOGF
#endif

#ifdef GEOFENCE_HILOGE
#undef GEOFENCE_HILOGE
#endif

#ifdef GEOFENCE_HILOGW
#undef GEOFENCE_HILOGW
#endif

#ifdef GEOFENCE_HILOGI
#undef GEOFENCE_HILOGI
#endif

#ifdef GEOFENCE_HILOGD
#undef GEOFENCE_HILOGD
#endif

// param of log interface, such as GEOFENCE_HILOGF.
enum GeofenceSubModule {
    GEOFENCE_MODULE_INNERKIT = 0,
    GEOFENCE_MODULE_SERVICE,
    GEOFENCE_MODULE_JS_NAPI,
    GEOFENCE_MODULE_COMMON,
    GEOFENCE_MODULE_BUTT,
};

// 0xD002900: subsystem:Msdp module:Geofence, 8 bits reserved.
static constexpr unsigned int BASE_MSDP_DOMAIN_ID = 0xD002900;

enum GeofenceDomainId {
    GEOFENCE_INNERKIT_DOMAIN = BASE_MSDP_DOMAIN_ID + GEOFENCE_MODULE_INNERKIT,
    GEOFENCE_SERVICE_DOMAIN,
    GEOFENCE_JS_NAPI,
    GEOFENCE_COMMON,
    GEOFENCE_BUTT,
};

static constexpr OHOS::HiviewDFX::HiLogLabel GEOFENCE_LABEL[GEOFENCE_MODULE_BUTT] = {
    {LOG_CORE, GEOFENCE_INNERKIT_DOMAIN, "GeofenceClient"},
    {LOG_CORE, GEOFENCE_SERVICE_DOMAIN, "GeofenceService"},
    {LOG_CORE, GEOFENCE_JS_NAPI, "GeofenceJsNapi"},
    {LOG_CORE, GEOFENCE_COMMON, "GeofenceCommon"},
};

// In order to improve performance, do not check the module range.
// Besides, make sure module is less than GEOFENCE_MODULE_BUTT.
#define GEOFENCE_HILOGF(module, ...) (void)OHOS::HiviewDFX::HiLog::Fatal(GEOFENCE_LABEL[module], __FORMATED(__VA_ARGS__))
#define GEOFENCE_HILOGE(module, ...) (void)OHOS::HiviewDFX::HiLog::Error(GEOFENCE_LABEL[module], __FORMATED(__VA_ARGS__))
#define GEOFENCE_HILOGW(module, ...) (void)OHOS::HiviewDFX::HiLog::Warn(GEOFENCE_LABEL[module], __FORMATED(__VA_ARGS__))
#define GEOFENCE_HILOGI(module, ...) (void)OHOS::HiviewDFX::HiLog::Info(GEOFENCE_LABEL[module], __FORMATED(__VA_ARGS__))
#define GEOFENCE_HILOGD(module, ...) (void)OHOS::HiviewDFX::HiLog::Debug(GEOFENCE_LABEL[module], __FORMATED(__VA_ARGS__))

} // namespace Msdp
} // namespace OHOS

#else

#define GEOFENCE_HILOGF(...)
#define GEOFENCE_HILOGE(...)
#define GEOFENCE_HILOGW(...)
#define GEOFENCE_HILOGI(...)
#define GEOFENCE_HILOGD(...)

#endif // CONFIG_HILOG

#endif // GEOFENCE_HILOG_WRAPPER_H
